//
//  TruthTable.cpp
//  MATH233_iLab1
//
//  Created by Ronald Ram on 1/13/13.
//  Copyright (c) 2013 Ronald Ram. All rights reserved.
//


/*
 ============================
    TRUTH TABLE RESULTS:
 ============================
    P       Q       R
    T       T       T
    T       T       F
    T       F       T
    T       F       F
    F       F       F
    F       T       F
    F       F       T
    F       T       T
 ============================
*/
#include "TruthTable.h"


TruthTable::TruthTable()
{
    //cout << "This is TruthTable Constructor..." << endl;
    p = NULL; q = NULL; r = NULL;
}


//Getter/Setter - P
bool TruthTable::getP() { return this->p; }
void TruthTable::setP(string p_)
{
    if ( p_ == "T" || p_ == "t" ) { this->p = true;
    }
    else { this->p = false; }
}

//Getter/Setter - Q
bool TruthTable::getQ() { return this->q; }
void TruthTable::setQ(string q_)
{
    if ( q_ == "T" || q_ == "t" ) { this->q = true;
    }
    else { this->q = false; }
}

//Getter/Setter - R
bool TruthTable::getR() { return this->r; }
void TruthTable::setR(string r_)
{
    if ( r_ == "T" || r_ == "t" ) { this->r = true;
    }
    else { this->r = false; }
}



void TruthTable::LogicGame()
{
    //cout << endl;
    TruthTable_P();
    TruthTable_Q();
    TruthTable_R();
    cout << endl;
}


void TruthTable::TruthTable_P()
{
    //P is True
    if ( getP() )
    {
        //p=T q=T r=T
        if ( getQ() && getR() ) {
            cout << "A says: A, B, & C are telling the truth: TRUE." << endl;
        }
        //p=T q=T r=F
        else if ( getQ() && !getR() ) {
            cout << "A says: A, & B are telling the truth: TRUE." << endl;
        }
        //p=T q=F r=T
        else if ( !getQ() && getR() ) {
            cout << "A says: A, & C are telling the truth: TRUE." << endl;
        }
        //p=T q=F r=F
        else if ( !getQ() && !getR() ) {
            cout << "A says: B & C are lying: TRUE." << endl;
        }
    }
    //P is False
    else if ( !getP() )
    {
        //p=F q=T r=T
        if ( getQ() && getR() ) {
            cout << "A says: B & C are lying: FALSE." << endl;
        }
        //p=F q=F r=T
        else if ( !getQ() && getR() ) {
            cout << "A says: A, & B are telling the truth: FALSE." << endl;
        }
        //p=F q=T r=F
        else if ( getQ() && !getR() ) {
            cout << "A says: A, & C are telling the truth: FALSE." << endl;
        }
        //p=F q=F r=F
        else if ( !getQ() && !getR() ) {
            cout << "A says: A, B, & C are telling the truth: FALSE." << endl;
        }

    }
}

void TruthTable::TruthTable_Q()
{
    //Q is True
    if ( getQ() )
    {
        //q=T p=T r=T
        if ( getP() && getR() ) {
            cout << "B says: B, A, & C are telling the truth: TRUE." << endl;
        }
        //q=T p=T r=F
        else if ( getP() && !getR() ) {
            cout << "B says: B & A are telling the truth: TRUE." << endl;
        }
        //q=T p=F r=F
        else if ( !getP() && !getR() ) {
            cout << "B says: A & C are lying: TRUE." << endl;
        }
        //q=T p=F r=T
        else if ( !getP() && getR() ) {
            cout << "B says: B & C are telling the truth: TRUE." << endl;
        }
    }
    //Q is False
    else if ( !getQ() )
    {
        //q=F p=T r=T
        if ( getP() && getR() ) {
            cout << "B says: A & C are lying: FALSE." << endl;
        }
        //q=F p=T r=F
        else if ( getP() && !getR() ) {
            cout << "B says: B & C are telling the truth: FALSE." << endl;
        }
        //q=F p=F r=F
        else if ( !getP() && !getR() ) {
            cout << "B says: B, A, & C are telling the truth: FALSE." << endl;
        }
        //q=F p=F r=T
        else if ( !getP() && getR() ) {
            cout << "B says: B & A are telling the truth: FALSE." << endl;
        }
    }
}

void TruthTable::TruthTable_R()
{
    //R is True
    if ( getR() )
    {
        //r=T p=T q=T
        if ( getP() && getQ() ) {
            cout << "C says: C, A, & B are telling the truth: TRUE." << endl;
        }
        //r=T p=T q=F
        else if ( getP() && !getQ() ) {
            cout << "C says: C & A are telling the truth: TRUE." << endl;
        }
        //r=T p=F q=F
        else if ( !getP() && !getQ() ) {
            cout << "C says: A & B are lying: TRUE." << endl;
        }
        //r=T p=F q=T
        else if ( !getP() && getQ() ) {
            cout << "C says: C & B are telling the truth: TRUE." << endl;
        }
    }
    //R is False
    else if ( !getR() )
    {
        //r=F p=T q=T  
        if ( getP() && getQ() ) {
            cout << "C says: A & B are lying: FALSE." << endl;
        }
        //r=F p=T q=F
        else if ( getP() && !getQ() ) {
            cout << "C says: C & B are telling the truth: FALSE." << endl;
        }
        //r=F p=F q=F
        else if ( !getP() && !getQ() ) {
            cout << "C says: C, A, & B are telling the truth: FALSE." << endl;
        }
        //r=F p=F q=T
        else if ( !getP() && getQ() ) {
            cout << "C says: C & A are telling the truth: FALSE." << endl;
        }
    }
}


